package cn.hchaojie.camp.javafx.animation;

import javafx.animation.Interpolator;
import javafx.animation.RotateTransition;
import javafx.animation.Transition;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;

public class DemoRotate extends Application {

	@Override
	public void start(Stage stage) throws Exception {
		Scene scene = new Scene(createContents(), 600, 300);
		
		stage.setScene(scene);
		stage.show();
	}
	
	// 在这里创建页面布局
	private Parent createContents() {
		StackPane stack = new StackPane();
		
		String url = getClass().getResource("mnls.png").toExternalForm();
		ImageView image = new ImageView(url);

		image.setFitHeight(100);
		image.setPreserveRatio(true);
		
		RotateTransition rt = new RotateTransition(
				Duration.millis(2000), image);
		rt.setInterpolator(Interpolator.EASE_BOTH);	
		rt.setByAngle(180);
		
		rt.setCycleCount(Transition.INDEFINITE);
		rt.setAutoReverse(true);
		rt.play();
		
		stack.getChildren().add(image);

		return stack;
	}

	public static void main(String[] args) {
		launch(args);
	}
}
